// 导入path模块
const path = require("path")
const HtmlWebpackPlugin = require("html-webpack-plugin")
module.exports = {
    mode: "production",
    // 入口
    entry: "./src/main.js",
    //出口=目录名+文件名
    output: {
        path: path.resolve(__dirname, "dist"),
        filename: "build.js"
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: "./pubilc/index.html"
        })
    ],
    devServer: {
        port: 3000,
    },
    module: {
        rules: [{
                test: /\.css$/i,
                use: ["style-loader", "css-loader"],
            },
            {
                test: /\.less$/i,
                use: ["style-loader", "css-loader", "less-loader"],
            },
            {
                test: /\.(png|gif|jpe?g|svg|webp)$/i,
                type: "asset",
                generator: {
                    filename: "image/[hash:20][ext]"
                }
            },
            {
                test: /\.(eot|svg|ttf|woff2?)$/i,
                type: "asset/resource",
                generator: {
                    filename: "font/[name].[hash:6][ext]"
                }
            },
            {
                test: /\.js$/i,
                exclude: /node_modules/,
                use: {
                    loader: "babel-loader",
                    options: {
                        presets: ["@babel/preset-env"]
                    }
                }
            }
        ],
    },

}